package com.albertyjz.juc;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureDemo {
    public static void main(String[] args) throws Exception{
        CompletableFuture<Void> completableFuture=CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName()+"没有返回，Update mysql ok");
        });
        completableFuture.get();

        CompletableFuture<Integer> completableFuture1=CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+"\tcompletableFuture1");
            //int age=1/0;
            return 1024;
        });
        //whenComplete是BiConsumer，里面填写两个参数
        System.out.println(completableFuture1.whenComplete((t,u)->{
            System.out.println("t"+t);
            System.out.println("u"+u);
        }).exceptionally(f->{
            System.out.println("异常"+f.getMessage());
            return 4444;
        }).get());
    }
}
